package com.frame.pageform.remote;

/**
 * 远程调用工厂
 */
import java.util.*;
import com.frame.pageform.ConfigFactory;

import net.sf.cglib.proxy.Enhancer;


public class RemoteCallFactory {

	private static Map map=new HashMap();

	public static Object create(Class c,String serverName) throws Exception{
		Object bean= map.get(c);
		if(bean==null){
			RemoteConfig config=(RemoteConfig)ConfigFactory.getBean(RemoteConfig.class);
			if(config.getServer(serverName)!=null){
				RemoteProxy  proxy=new RemoteProxy(new RemoteCall(config.getServer(serverName),c.getName()));
				bean=Enhancer.create(c, proxy);
			}else
				bean=c.newInstance();
			map.put(c, bean);
		}
		return bean;
	}
}
